package com.lczyfz.istep.modules.teach.service;

/**
 * Created by Alisa Ye on 2017/2/28.
 */

import java.util.List;

import com.lczyfz.istep.common.constants.DeleteFlag;
import com.lczyfz.istep.common.utils.StringUtils;
import com.lczyfz.istep.modules.sys.dao.RoleDao;
import com.lczyfz.istep.modules.sys.service.SystemService;
import com.lczyfz.istep.modules.sys.utils.UserUtils;
import com.lczyfz.istep.modules.teach.entity.TeachClass;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lczyfz.istep.common.persistence.Page;
import com.lczyfz.istep.common.service.CrudService;
import com.lczyfz.istep.modules.teach.entity.TeachStudent;
import com.lczyfz.istep.modules.teach.dao.TeachStudentDao;
import com.lczyfz.istep.common.constants.StudentRole;


public class TeachTeacherService extends CrudService<TeachStudentDao, TeachStudent>{

    @Autowired
    TeachStudentDao teachStudentDao ;
    @Autowired
    RoleDao roleDao;
    @Autowired
    SystemService systemService;

    public TeachStudent get(String id) {
        return super.get(id);
    }

    public List<TeachStudent> findList(TeachStudent teachStudent) {
        return super.findList(teachStudent);
    }

    public Page<TeachStudent> findPage(Page<TeachStudent> page, TeachStudent teachStudent) {
        return super.findPage(page, teachStudent);
    }


    @Transactional(readOnly = false)
    public void save(TeachStudent teachStudent) {
        super.save(teachStudent);
    }

    @Transactional(readOnly = false)
    public void delete(TeachStudent teachStudent) {
        super.delete(teachStudent);
    }

    @Transactional(readOnly = false)
    public int update(TeachStudent teachStudent){
        return teachStudentDao.update(teachStudent);
    }



    //添加、修改学生
    @Transactional(readOnly = false)
    public void saveStudent(TeachStudent teachStudent){
        if(StringUtils.isBlank(teachStudent.getId())){
            teachStudent.preInsert();
            teachStudentDao.insert(teachStudent);
            //插入用户和角色关联表数据
            teachStudentDao.studentInsertUserRole(teachStudent.getId(), systemService.getRoleByEnname(StudentRole.student).getId());
        }else {
            teachStudent.preUpdate();
            teachStudentDao.update(teachStudent);
        }
    }

    //获取所有班级名
    public List<TeachClass> findAllClassList(){
        return teachStudentDao.findAllClassList(DeleteFlag.deleteFlag);
    };

    //获取所有没有所属班级的学生
//    public List<TeachStudent> findAllBatchAddStudentList(){
//        return teachStudentDao.findAllBatchAddStudentList(DeleteFlag.deleteFlag);
//    };

    //获取所有登录名
    public List<TeachStudent> findAllLoginName(){
        return teachStudentDao.findAllLoginName(DeleteFlag.deleteFlag);
    }

    //根据登录名获取学生记录
    public TeachStudent findStudentByLoginName(String loginName) {
        return teachStudentDao.findStudentByLoginName(loginName,DeleteFlag.deleteFlag);
    }



}
